package org.moda.dsl.source;

import org.moda.common.Either;
import org.moda.dsl.source.format.Formatter;
import org.moda.dsl.source.loader.Loader;

import java.util.List;

class GenericDataSource implements DataSource {
    private final Formatter format;
    private final Either<Throwable, byte[]> rawData;

    public GenericDataSource(Loader loader, Formatter format) {
        // this.loader = loader;
        this.format = format;
        this.rawData = loader.load();
    }

    @Override
    public Either<Throwable, List<List<String>>> getData() {
        Either<Throwable, List<List<String>>> rs = rawData.mapRight(format::parse).fold(Either::left, r -> r);
        return rs;
    }

}